// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InstrumentListExpo.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge
{
    #region Using Directives

    using System;

    using Org.OpenTrader.Framework.Enums;
    using Org.OpenTrader.Framework.Forge.Enums;
    using Org.OpenTrader.Framework.Forge.Interfaces;

    #endregion

    /// <summary>
    /// The instrument expo.
    /// </summary>
    public class InstrumentListExpo : Expo<IInstrumentExpoCell>
    {
        private static readonly Identity Identity = Identity.Create(System.Reflection.MethodBase.GetCurrentMethod());

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="InstrumentListExpo"/> class.
        /// </summary>
        public InstrumentListExpo()
        {
            Logging.Log(Identity, ELogLevel.Debug, () => string.Format("Creating new InstrumentListExpo"));

            // Traded
            this[EExpoCellType.Traded] = new InstrumentListExpoCell(null, EExpoCellType.Traded);

            // Working
            this[EExpoCellType.Working] = new InstrumentListExpoCell(null, EExpoCellType.Working);

            // Inventory
            this[EExpoCellType.Inventory] = new InstrumentListExpoCell(null, EExpoCellType.Inventory);

            // Target
            this[EExpoCellType.Target] = new InstrumentListExpoCell(null, EExpoCellType.Target);

            // Pending
            this[EExpoCellType.Pending] = new InstrumentListExpoCell(null, EExpoCellType.Pending);
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// The add.
        /// </summary>
        /// <param name="i">
        /// The i.
        /// </param>
        public void Add(IInstrument i)
        {
            // Check Instrument
            if (i == null)
            {
                Logging.Log(Identity, ELogLevel.Error, () => string.Format("Add : Cannot add instrument, Unknown Instrument"));
                return;
            }

            // Check Instrument Static Data
            if (i.InstrumentStaticData == null)
            {
                Logging.Log(Identity, ELogLevel.Error, () => string.Format("Add : Cannot add instrument, Unknown Instrument Static Data"));
                return;
            }

            // Add Instrument to expo cells
            foreach (var scope in Enum.GetValues(typeof(EExpoCellType)))
            {
                ((InstrumentListExpoCell)this[(EExpoCellType)scope]).Add(i);
            }
        }

        /// <summary>
        /// The remove.
        /// </summary>
        /// <param name="i">
        /// The i.
        /// </param>
        public void Remove(IInstrument i)
        {
            // Check Instrument
            if (i == null)
            {
                Logging.Log(Identity, ELogLevel.Error, () => string.Format("Remove : Cannot remove instrument, Unknown Instrument"));
                return;
            }

            // Check Instrument Static Data
            if (i.InstrumentStaticData == null)
            {
                Logging.Log(Identity, ELogLevel.Error, () => string.Format("Remove : Cannot remove instrument, Unknown Instrument Static Data"));
                return;
            }

            // Remove Instrument to expo cells
            foreach (var scope in Enum.GetValues(typeof(EExpoCellType)))
            {
                ((InstrumentListExpoCell)this[(EExpoCellType)scope]).Remove(i);
            }
        }

        #endregion
    }
}